
Partial Class WebForm_ManageTrainingTeacher_SearchTrainingTeacher
    Inherits My.MyUserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            RaiseEvent Loaded(Me, New EventArgs)
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub

    Protected Sub gv_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gv.RowDeleting
        If Me.DelData(e.RowIndex) = True Then
            Me.BindGV()
        End If

    End Sub

    Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
        Dim key As DataKey = Me.gv.DataKeys(e.RowIndex)
        Me.SelectedTeacherID = key("TeacherID")
        RaiseEvent Updating(Me, New EventArgs)
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click        
        RaiseEvent Adding(Me, New EventArgs)
    End Sub
End Class

Partial Class WebForm_ManageTrainingTeacher_SearchTrainingTeacher
    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select t.* ")
        sql.AppendFormat(" from TrainingTeacher t ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat(Me.GetWhereSQL())

        dt = dat.GetData(sql)
        Me.gv.DataSource = dt
        Me.gv.DataBind()
    End Sub

    Public Sub BindGV(ByVal teacherID As String)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select t.* ")
        sql.AppendFormat(" from TrainingTeacher t ")
        sql.AppendFormat("where 1=1 ")
        'sql.AppendFormat("and t.TeacherID = '{0}' ", teacherID)
        sql.AppendFormat("and t.TeacherName = '{0}' ", teacherID)
        dt = dat.GetData(sql)
        Me.gv.DataSource = dt
        Me.gv.DataBind()
    End Sub

    Private Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        If Me.txtTeacherName.Text <> "" Then
            sql.AppendFormat("and t.TeacherName like '%{0}%'", Me.txtTeacherName.Text)
        End If
        If Me.txtDescription.Text <> "" Then
            sql.AppendFormat("and t.Description like '%{0}%'", Me.txtDescription.Text)
        End If

        Return sql.ToString()
    End Function

    Private Function DelData(ByVal rowIndex As Integer) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        Dim key As DataKey = Me.gv.DataKeys(rowIndex)

        Using scope As New Transactions.TransactionScope

            sql.Length = 0
            sql.AppendFormat("delete TrainingTeacher ")
            sql.AppendFormat(" where TeacherID = '{0}' ", key("TeacherID"))
            dat.AccData(sql)
            scope.Complete()
        End Using

        Return True
    End Function

    Public Property SelectedTeacherID() As String
        Get
            Return ViewState("SelectedTeacherID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedTeacherID") = value
        End Set
    End Property
    Public Property SelectedTeacherName() As String
        Get
            Return ViewState("SelectedTeacherName")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedTeacherName") = value
        End Set
    End Property


    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event Adding(ByVal source As Object, ByVal e As EventArgs)
    Public Event Updating(ByVal source As Object, ByVal e As EventArgs)
End Class
